library(tidyverse)

#FIGURE S10####
#import data
load("survey.RData")

#collective guilt
stol$guilt1 <- as.numeric(as.factor(stol$guilt1))
stol$guilt2 <- as.numeric(as.factor(stol$guilt2))
stol$guilt3 <- as.numeric(as.factor(stol$guilt3))
stol$guilt_average <- (stol$guilt1 + stol$guilt2 + stol$guilt3)/3

#democratic collapse
stol$collapse1 <- as.numeric(as.factor(stol$collapse1))
stol$collapse2 <- as.numeric(as.factor(stol$collapse2))
stol$collapse3 <- as.numeric(as.factor(stol$collapse3))
stol$collapse_average <- (stol$collapse1 + stol$collapse2 + stol$collapse3)/3

#empathy
stol$empathy1 <- as.numeric(as.factor(stol$empathy1))
stol$empathy2 <- as.numeric(as.factor(stol$empathy2))
stol$empathy3 <- as.numeric(as.factor(stol$empathy3))
stol$empathy_average <- (stol$empathy1 + stol$empathy2 + stol$empathy3)/3

#local norms
stol$local_norms1 <- as.numeric(as.factor(stol$local_norms1))
stol$local_norms2 <- as.numeric(as.factor(stol$local_norms2))
stol$local_norms3 <- as.numeric(as.factor(stol$local_norms3))
stol$local_norms4 <- as.numeric(as.factor(stol$local_norms4))
stol$local_norms_average <- (stol$local_norms1 + stol$local_norms2 + stol$local_norms3 + stol$local_norms4)/4


#Mean values for each process
to_plot <- data.frame(average_score = c(mean(stol$guilt_average), mean(stol$collapse_average),
                                        mean(stol$local_norms_average),  mean(stol$empathy_average)),
                      process = c("Collective Guilt", "Awareness of Atrocities", "Local Social Norms", "Empathy"))
ggplot(to_plot, aes(average_score, reorder(process, average_score))) +
  geom_bar(stat = "identity") +
  theme_bw() +
  labs(x = "Average score", y = "") +
  theme(axis.text.x = element_text(size = "14"), axis.text.y = element_text(size = "14"))
